<template>
  <div class="app-container" >
    <el-row type="flex" class="mar-b__15">
      <el-col :span="16">
        <el-select 
          v-model="listQuery.categoryId" 
          placeholder="请选择类别"
          @change="getList"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.categoryName"
            :value="item.categoryId">
          </el-option>
        </el-select>
      </el-col>
      <el-col  :span="4"><div class="grid-content bg-purple"></div></el-col>
      <el-col :span="6">
        <el-col class="mar-r__15" :span="14"><el-input v-model="listQuery.company" placeholder="请输入内容"></el-input></el-col>
        <el-col :span="8">
          <el-button  type="primary" icon="plus" @click="getList" >查询
          </el-button>
        </el-col>
      </el-col>
    </el-row>

    <el-table 
      :data="list" 
      v-loading.body="listLoading" 
      element-loading-text="拼命加载中" 
      border 
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="序号" width="80">
        <template slot-scope="scope">
          <span v-text="getIndex(scope.$index)"> </span>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="articleTitle" label="文档标题" style="width: 60px;"></el-table-column>
      <el-table-column align="center" prop="username" label="作者ID" style="width: 30px;"></el-table-column>
      <el-table-column align="center" prop="nickname" label="作者名称" style="width: 30px;"></el-table-column>
      <el-table-column align="center" prop="categoryName" label="所属类别" style="width: 10px;"></el-table-column>
      <el-table-column align="center" prop="company" label="所属公司" style="width: 30px;"></el-table-column>
      <el-table-column align="center" prop="companyCode" label="公司代码" style="width: 10px;"></el-table-column>
      <el-table-column
        align="center"
        prop="tag"
        label="文章状态"
      >
        <template slot-scope="scope">
          <el-tag
            :type="dataColorFun(stateCode[scope.row.status]) ? 'success' : 'danger'" 
            close-transition>{{stateCode[scope.row.status]}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="updateTime" label="最后更新时间" style="width: 60px;"></el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="listQuery.currentPage"
      :page-size="10"
      layout="prev, pager, next, jumper"
      :total="totalCount">
    </el-pagination>
  </div>
</template>
<script>
  import { authorState, dataColorFun } from '../../utils/state.code'
  export default {
    data() {
      return {
        stateCode: authorState,
        totalCount: 0, //分页组件--数据总条数
        list: [],//表格的数据
        listLoading: false,//数据加载等待动画
        listQuery: {
          totalNum: 1,
          pageNum: 1,//页码
          pageRow: 10,//每页条数
          company: '', // 所属公司
          categoryId: '' //所属类别
        },
        input: '',
        dialogStatus: 'create',
        dialogFormVisible: false,
        textMap: {
          update: '编辑',
          create: '创建文章'
        },
        categoryCode: 0, // 10001  或者  10002 或者 0
        tempArticle: {
          id: "",
          content: ""
        },
        options: [],
        value: '',
      }
    },
    created() {
      this.getList();
      this.categoryFun()
    },
    methods: {
      getList() {
        //查询列表
        // if (!this.hasPerm('article:list')) {
        //   return
        // }
        if(this.listQuery.categoryId==1){
          this.listQuery.categoryId = ''
        }
        this.listLoading = true;
        this.api({
          url: "/article/allListArticle?",
          method: "get",
          params: this.listQuery
        }).then(data => {
          this.listLoading = false;
          this.list = data.list;
          this.listQuery.totalNum = data.totalPage;
          this.totalCount = data.totalCount;
        })
      },
      handleSizeChange(val) {
        //改变每页数量
        this.listQuery.pageRow = val
        this.handleFilter();
      },
      handleCurrentChange(val) {
        //改变页码
        this.listQuery.pageNum = val
        this.getList();
      },
      getIndex($index) {
        //表格序号
        return (this.listQuery.pageNum - 1) * this.listQuery.pageRow + $index + 1
      },
      showCreate() {
        //显示新增对话框
        this.tempArticle.content = "";
        this.dialogStatus = "create"
        this.dialogFormVisible = true
      },
      showUpdate($index) {
        //显示修改对话框
        this.tempArticle.id = this.list[$index].id;
        this.tempArticle.content = this.list[$index].content;
        this.dialogStatus = "update"
        this.dialogFormVisible = true
      },
      categoryFun() {
        //类别
        this.api({
          url: "/article/category",
          method: "post",
          data: {
            categoryCode: 0
          }
        }).then((data) => {
          this.options = data.list
        })
      },
      changeFun(){
        this.getList();
      },
      searchFun(){
        this.getList();
      },
      dataColorFun,
    }
  }
</script>

<style lang="stylus">


</style>

